package com.supreme.cacheserver.service;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Service
public class RedisService {

    @Resource
    private RedisTemplate<String, Serializable> redisTemplate;

    public <T extends Serializable> void setRedisStr(String key, T value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public <T extends Serializable> void setRedisStrExpire(String key, T value, long time, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, value, time, timeUnit);
    }

    public Serializable getRedisStr(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public <T extends Serializable> void setHashAll(String key, Map<?, T> value) {
        redisTemplate.opsForHash().putAll(key, value);
    }

    public Map<Object, Object> getHashEntries(String key) {
        return redisTemplate.opsForHash().entries(key);
    }

    public <T extends Serializable> void setHashItem(String key, Object hashKey, T value) {
        redisTemplate.opsForHash().put(key, hashKey, value);
    }

    public Object getHashItem(String key, Object hashKey) {
        return redisTemplate.opsForHash().get(key, hashKey);
    }

    public void setList() {

    }
}
